local kumo = fk.CreateSkill{
  name = "pegasus__kumo",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable{
  ["pegasus__kumo"] = "枯墨",
  [":pegasus__kumo"] = "锁定技，你使用未指定其他角色为目标的牌时，弃置4-X张牌并回复一点体力；然后你失去至少一个技能直到回合结束并摸等量的牌。",

  ["pegasus__kumo-discard"] = "枯墨：请弃置%arg张牌",
  ["pegasus__kumo-chuanwu"] = "枯墨：请失去至少一个技能直到回合结束，摸等量的牌",
}

---@param player Player
---@return string[]
local getPlayerSkills = function (player)
  local skills = {}
  for _, s in ipairs(player.player_skills) do
    if s:isPlayerSkill(player) then
      table.insertIfNeed(skills, s.name)
    end
  end
  return skills
end

kumo:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(kumo.name) and player == target
    and #data.tos == 1 and data.tos[1] == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = math.max(0, 4 - #getPlayerSkills(player))
    local cards = room:askToDiscard(player, {
      min_num = num,
      max_num = num,
      skill_name = kumo.name,
      cancelable = false,
      include_equip = true,
      prompt = "pegasus__kumo-discard:::" .. num,
    })

    if player:isWounded() then
      room:recover{
        who = player,
        recoverBy = player,
        num = 1,
        skillName = kumo.name,
      }
    end

    if player:isAlive() then
      local op = room:askToChoices(player, {
        choices = getPlayerSkills(player),
        min_num = 1,
        max_num = 999,
        detailed = true,
        skill_name = kumo.name,
      })

      table.forEach(op, function (skill)
        room:addTableMarkIfNeed(player, "pegasus__kumo", skill)
      end)
      room:handleAddLoseSkills(player, table.concat(table.map(op, function (e) return "-" .. e end), "|"))

      if player:isAlive() then
        player:drawCards(#op, kumo.name)
      end
    end
  end
})

kumo:addEffect(fk.TurnEnd, {
  can_refresh = function (self, event, target, player, data)
    return #player:getTableMark("pegasus__kumo") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local skills = player:getTableMark("pegasus__kumo")
    room:setPlayerMark(player, "pegasus__kumo", 0)
    room:handleAddLoseSkills(player, table.concat(skills, "|"))
  end
})

return kumo